/*
 * Copyright 2018-9-30 20:11:44 The JA-SIG Collaborative. All rights reserved.
 * distributed with thi file and available online at
 */
package com.lap.scp.erp.core.impl;

import java.util.Collections;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.lap.scd.commons.core.exception.ManagerException;
import com.lap.scd.commons.page.Page;
import com.lap.scp.erp.core.ReceivablesManager;
import com.lap.scp.erp.dal.ReceivablesDAO;
import com.lap.scp.erp.domain.ReceivablesDO;
import com.lap.scp.erp.query.ReceivablesQueryVO;

/**
 * <pre>
 * 收款信息，记录合同的收款信息，可以有多条记录，并记录每个阶段的金额业务代码默认实现类，这里提供最小元素原子操作，所以尽量少在该类中做流程代码。
 * 业务流程代码应该写在AO中。
 * </pre>
 * 
 * @author 劳水生 Exp
 * @Date 2018-9-30 20:11:44
 * @since 2.0.0
 */
@Service("receivablesManager")
public class DefaultReceivablesManager implements ReceivablesManager {
	/**
	 * 收款信息，记录合同的收款信息，可以有多条记录，并记录每个阶段的金额数据操作对象
	 */
	@Resource
	private ReceivablesDAO receivablesDAO;

	@Override
	public void insertReceivables(ReceivablesDO receivablesDO) throws ManagerException {
		receivablesDAO.insertReceivables(receivablesDO);
	}

	@Override
	public int deleteById(Integer receivablesId) throws ManagerException {
		return receivablesDAO.deleteById(receivablesId);
	}

	@Override
	public ReceivablesDO queryById(Integer receivablesId) throws ManagerException {
		return receivablesDAO.queryById(receivablesId);
	}

	@Override
	public List<ReceivablesDO> queryByContractId(Integer contractId) throws ManagerException {
		return receivablesDAO.queryByContractId(contractId);
	}

	@Override
	public List<ReceivablesDO> queryPage(Page page, ReceivablesQueryVO queryVO) throws ManagerException {
		int count = receivablesDAO.countPage(queryVO);
		if (count == 0) {
			return Collections.emptyList();
		} else {
			page.setTotalItem(count);
			return receivablesDAO.queryPage(page, queryVO);
		}
	}

	@Override
	public int updateReceivables(ReceivablesDO receivablesDO) throws ManagerException {
		return receivablesDAO.updateReceivables(receivablesDO);
	}

}
